package com.ship.service.impl;

import com.ship.commens.Result;
import com.ship.mapper.ShipMapper;
import com.ship.mapper.ShipStatusMapper;
import com.ship.mapper.UserMapper;
import com.ship.model.HumiditysAndTimes;
import com.ship.model.ShipNamesAndUserCounts;
import com.ship.model.TemperatureAndTimes;
import com.ship.service.EcharsService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class EcharsServiceImpl implements EcharsService {

    @Resource
    private ShipMapper shipMapper;

    @Resource
    private UserMapper userMapper;

    @Resource
    private ShipStatusMapper shipStatusMapper;

    @Override
    public Result findShipWithUserCount() {
        String[] names = shipMapper.selectNamesOrderById();

        Long[] counts = userMapper.selectUserCountsOrderByShip_id();

        Result result = new Result();
        ShipNamesAndUserCounts data = new ShipNamesAndUserCounts();
        data.setNames(names);
        data.setCounts(counts);
        result.setData(data);
        return result;
    }

    @Override
    public Result findTemperaturesByShipId(Long shipId) {
        /*温度 和 时间*/
        List<TemperatureAndTimes> temperatureAndTimesList =  shipStatusMapper.selecTemperaturesAndTimes(shipId);
        Result result = new Result();
        result.setData(temperatureAndTimesList);
        return result;
    }

    @Override
    public Result findHumiditysByShipId(Long shipId) {
        /*湿度和时间*/
        List<HumiditysAndTimes> humiditysAndTimesList = shipStatusMapper.selectHumiditysAndTimes(shipId);
        Result result = new Result();
        result.setData(humiditysAndTimesList);
        return result;
    }
}
